<template>
  <el-row :gutter="20">
    <el-col :span="10" :push="5">
      <el-form ref="form" :model="HouseRentDetailVo" label-width="80px">
        <el-form-item label="id">
          <el-input v-model="HouseRentDetailVo.id" disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="房东姓名">
          <el-input v-model="HouseRentDetailVo.hostRoughVo.name"></el-input>
        </el-form-item>
        <el-form-item label="房东联系方式">
          <el-input v-model="HouseRentDetailVo.hostRoughVo.phone"></el-input>
        </el-form-item>
        <el-form-item label="房屋地点">
          <el-input v-model="HouseRentDetailVo.location"></el-input>
        </el-form-item>
        <el-form-item label="出租价格">
          <el-input v-model="HouseRentDetailVo.price"></el-input>
        </el-form-item>
        <el-form-item label="房屋标签">
          <el-tag
            :key="tag"
            v-for="tag in dynamicTags"
            closable
            :disable-transitions="false"
            @close="handleClose(tag)">
            {{tag}}
          </el-tag>
          <el-input
            class="input-new-tag"
            v-if="inputVisible"
            v-model="inputValue"
            ref="saveTagInput"
            size="small"
            @keyup.enter.native="handleInputConfirm"
            @blur="handleInputConfirm"
          >
          </el-input>
          <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
        </el-form-item>
        <el-form-item label="距离">
          <el-input v-model="HouseRentDetailVo.distance"></el-input>
        </el-form-item>
        <el-form-item label="房屋面积">
          <el-input v-model="HouseRentDetailVo.area"></el-input>
        </el-form-item>
        <el-form-item label="客厅数量">
          <el-select v-model="HouseRentDetailVo.livingRoomAmount">
            <el-option v-for="(value,index) in numbers" :key="index" :value="value" :label="value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="卧室数量">
          <el-select v-model="HouseRentDetailVo.bedroomAmount">
            <el-option v-for="(value,index) in numbers" :key="index" :value="value" :label="value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="床数量">
          <el-select v-model="HouseRentDetailVo.bedAmount">
            <el-option v-for="(value,index) in numbers" :key="index" :value="value" :label="value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="卫生间">
          <el-select v-model="HouseRentDetailVo.toiletAmount">
            <el-option v-for="(value,index) in numbers" :key="index" :value="value" :label="value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房客数量">
          <el-select v-model="HouseRentDetailVo.roomerAmount">
            <el-option v-for="(value,index) in numbers" :key="index" :value="value" :label="value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房屋描述">
          <el-input type="textarea" v-model="HouseRentDetailVo.desc"></el-input>
        </el-form-item>
        <el-form-item label="详细介绍">
          <el-input type="textarea" v-model="HouseRentDetailVo.intro"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'HousingBasicInformationManagement',
  data () {
    return {
      HouseRentDetailVo: this.$route.params.HouseRentDetailVo,
      numbers: [],
      dynamicTags: this.$route.params.HouseRentDetailVo.tag.split(' '),
      inputVisible: false,
      inputValue: ''
    }
  },
  methods: {
    onSubmit () {
      alert(this.dynamicTags)
    },
    handleClose (tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },

    showInput () {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm () {
      let inputValue = this.inputValue
      if (inputValue) {
        this.dynamicTags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    }
  },
  mounted () {
    for (let i = 1; i < 99; i++) {
      this.numbers.push(i)
    }
  }
}
</script>

<style scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
